import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sptapp/basic/base_info.dart';
import 'package:sptapp/config/const.dart';
import 'package:sptapp/moudle/common_info.dart';
import 'package:sptapp/moudle/message.dart';
import 'package:sptapp/widget/common_widget.dart';

import '../../api/interface/user_api.dart';
import '../../api/request/response_data.dart';
import '../../widget/cache_image.dart';
import '../login/login.dart';

class MinInfoPage extends StatefulWidget {
  const MinInfoPage({super.key});

  @override
  State<MinInfoPage> createState() => _MinInfoPageState();
}

class _MinInfoPageState extends State<MinInfoPage> {

  bool isDisabled = false;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _getInfo();
  }
  _getInfo()async{
    getBaseUserInfo((){
      if(mounted){setState(() {});}
    });
  }

  List items = [
    {
      'name':'Avatar'.tr,
    },
    {
      'name':'Username'.tr,
    },
    {
      'name':'Email'.tr,
    },
    // {
    //   'name':'Region'.tr,
    // },
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: defaultBlackBgColor,
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 40.w),
        child: Column(
          children: [
            SizedBox(height: ScreenUtil().statusBarHeight + 40.w,),
            myCustomCenterTitleAppBar('Personal Information'),
            SizedBox(height: 60.w,),

            Container(
              padding: EdgeInsets.all(40.w),
              decoration: BoxDecoration(
                color: Color(0xff1e1d20),
                borderRadius: BorderRadius.circular(16.w)
              ),
              child: ListView.builder(itemBuilder: (ctx,index){
                return itemWidget(index);
              },itemCount: items.length,padding: EdgeInsets.zero,shrinkWrap: true,physics: NeverScrollableScrollPhysics(),)
              // Column(
              //   children: [
              //     Container(
              //       child: Image.asset('assets/home/home_person.png',width: 128.w,),
              //     ),
              //     SizedBox(height: 24.w,),
              //     Container(
              //       child: Row(
              //         crossAxisAlignment: CrossAxisAlignment.start,
              //         children: [
              //           Expanded(child: Column(
              //             crossAxisAlignment: CrossAxisAlignment.start,
              //             children: [
              //               Text('Username',style: TextStyle(
              //                 color: Color(0xff9A9A9A),
              //                 fontSize: 28.sp,
              //               ),),
              //               Text(baseUserInfo['nickname']??'',style: TextStyle(
              //                   color: Colors.white,
              //                   fontSize: 28.sp
              //               ))
              //             ],
              //           )),
              //           GestureDetector(
              //             onTap: (){
              //               Navigator.of(context).pushNamed('MinInfoChangeNickname').then((val){
              //                 if(mounted){setState(() {});}
              //               });
              //             },
              //             child: Text('Edit',style: TextStyle(
              //                 color: Color(0xff6C82FF),
              //                 fontSize: 32.sp
              //             ),),
              //           )
              //         ],
              //       ),
              //     ),
              //     SizedBox(height: 32.w,),
              //     Container(
              //       child: Row(
              //         crossAxisAlignment: CrossAxisAlignment.start,
              //         children: [
              //           Expanded(child: Column(
              //             crossAxisAlignment: CrossAxisAlignment.start,
              //             children: [
              //               Text('Email',style: TextStyle(
              //                 color: Color(0xff9A9A9A),
              //                 fontSize: 28.sp,
              //               ),),
              //               Text(baseUserInfo['email'] ??'',style: TextStyle(
              //                   color: Colors.white,
              //                   fontSize: 28.sp
              //               ))
              //             ],
              //           )),
              //         ],
              //       ),
              //     ),
              //   ],
              // ),
            )
          ],
        ),
      ),
    );
  }

  Widget itemWidget(int index){
    String value = '';
    if(index == 1){
      value = baseUserInfo['nickname']??'';
    }else if(index == 2){
      value = baseUserInfo['email']??'';
    }else if(index == 3){
      value = baseUserInfo['region']??'';
    }
    return GestureDetector(
      onTap: (){
        if(index == 0){
          Navigator.of(context).pushNamed('MinChangeAvatar').then((val){
            _getInfo();
          });
        }else if(index == 1){
          Navigator.of(context).pushNamed('MinInfoChangeNickname').then((val){
            if(mounted){setState(() {});}
          });
        }
      },
      child: Container(
        height: index == 0? 200.w:116.w,
        child: Row(
          children: [
            Container(
              child: Text(items[index]['name'],style: TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.w600,
                fontSize: 28.sp,
              ),),
            ),
            SizedBox(width: 24.w,),
            Expanded(child: Container(
              child: index == 0? Container(
                alignment: Alignment.centerRight,
                color: Colors.transparent,
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(8.w),
                  child: CacheImage(
                    image: baseUserInfo['avatar']??'assets/home/home_person.png',
                    placeholder: 'assets/home/home_person.png',
                    width: 128.w,
                    height: 128.w,
                    fit: BoxFit.fill,
                  ),
                ),
              ):
              Text(value,style: TextStyle(
                  color: Color.fromRGBO(255, 255, 255, 0.5),
                  fontSize: 28.sp,
                  fontWeight: FontWeight.w400
              ),maxLines: 1,overflow: TextOverflow.ellipsis,textAlign: TextAlign.right,),
            )),
            SizedBox(width: 12.w,),
            Visibility(child: Image.asset('assets/common/control_right.png',width: 48.w,),visible: index <2,)
          ],
        ),
      ),
    );
  }
}
